package com.example.concurrentprogramming8016.future.completablefuture;

import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionService;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author liyanhao
 * @Date 2023-01-08 20:07
 */
public class ThenComposeDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture future = CompletableFuture.supplyAsync(() -> {
            int number = (int) (Math.random() * 100);
            System.out.println("第一阶段:" + number);
            return number;
        }).thenCompose(param -> CompletableFuture.supplyAsync(() -> {
            int number = param * 3;
            System.out.println("第二阶段 " + number);
            return number;
        }));
        System.out.println("最终结果 " + future.get());
    }
}
